package cn.liwq.study.demo.netty.lab.mahjong.client.handler;

import cn.liwq.study.demo.netty.lab.mahjong.common.dto.HelloResponse;
import cn.liwq.study.demo.netty.lab.mahjong.common.enums.MessageManager;
import cn.liwq.study.demo.netty.lab.mahjong.common.protocol.MahjongProtocol;
import cn.liwq.study.demo.netty.lab.mahjong.common.protocol.MahjongProtocolHeader;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import lombok.extern.slf4j.Slf4j;

/**
 * @author lweiqiang
 * @date 2021/5/8
 */
@Slf4j
public class MahjongClientHandler extends SimpleChannelInboundHandler<MahjongProtocol> {
    @Override
    protected void channelRead0(ChannelHandlerContext ctx, MahjongProtocol mahjongProtocol)
            throws Exception {
        MahjongProtocolHeader header = mahjongProtocol.getHeader();
        if (header.getCmd() == MessageManager.HELLO_RESPONSE.getCmd()) {
            HelloResponse response = (HelloResponse) mahjongProtocol.getBody();
            log.info("server return: {}", response.getMessage());
        }
    }
}
